<?php

    $actions = array(
        array(
            'label'   => 'Štampaj', 
            'link'    => 'javascript:pdfFaktura(\'%s\')'
        ),
        array(
		    'label'   => 'Obriši', 
            'link'    => '/invoices/remove/%s',
            'confirm' => 'Da li želite da obrišete fakturu?',
            'options' => array( 'class'=>'delete' )
        )
    );
    
    if (empty($this->params->query['storno'])) {
        $actions[] = array(
            'label'   => 'storniraj', 
            'link'    => '/invoices/storno/%s',
            'confirm' => 'Da li želite da stornirate fakturu?',
            'options' => array( 'class'=>'delete' )
        );
    } else {
        $actions[] = array(
            'label'   => 'od-storniraj', 
            'link'    => '/invoices/storno/%s/0',
            'confirm' => 'Da li želite da od-stornirate fakturu?',
            'options' => array( 'class'=>'green' )
        );
    }

?>

<p>
    <?= $this->App->buttonLink('+ Nova Faktura', '/invoices/create') ?>
    <?= $this->Html->link('Kampanje', '/campaigns') ?> |
    <?= $this->Html->link('Uplate', '/payments') ?>
</p>
<?= $this->element('entity_table_filter', array(
    'filter' => array(
        'Aktivne'     => '/invoices',
        'Stornirane'  => '/invoices?storno=1'
    ),
    'selected' => $selectedTab
)) ?>
<?= $this->element('entity_table', array(
    'columns' => array(
        'Id'            => 'Invoice.id',
        'Broj'          => 'Invoice.number',
        'Kampanja'      => 'Campaign.label',
        'Datum'         => array('Invoice.date', function($row) {
            return date_local($row['Invoice']['date']); 
        }),
        'Datum valute'  => array('Invoice.date_valuta', function($row) {
            return date_local($row['Invoice']['date_valuta']);
        }),
        'Iznos'         => array(null, function($row){
            return currency_format($row['Invoice']['amount']);
        })
    ),
    'columnWidth' => array(
        'Id'            => '1%',
        'Kampanja'      => '50%',
        'Datum'         => '10%',
        'Datum valute'  => '10%'
    ),
    'links' => array(
        'Broj'     => array('/invoices/edit/%d', 'Invoice.id'),
        'Kampanja' => array('/campaigns/edit/%d', 'Campaign.id')
    ),
    'filter' => array(
        'Datum'        => ''.@$filter['Invoice']['date'],
        'Datum valute' => ''.@$filter['Invoice']['date_valuta'],
    ),
    'align'    => array(
        'Iznos' => 'right'
    ),
    'actions'  => $actions,
    'data'     => $invoices,
    'id'       => 'Invoice.id',
    'entity'   => 'invoices',
    'sort_by'  => $sort_by,
    'sort_dir' => $sort_dir,
    'cantDelete' => true
)) ?>